﻿using System;
using Entities.DataBase.Persistent;

namespace Entities.DataBase.Obj {

    public class PurchaseRecordUpdator {

        public string    Id             { get; set; }
        public int?      Count          { get; set; }
        public int?      Location       { get; set; }
        public double?   Cost           { get; set; }
        public double?   Postage        { get; set; }
        public double?   Rate           { get; set; }
        public string    OperatorId     { get; set; }
        public string    PostOperatorId { get; set; }
        public DateTime? DatePurchased  { get; set; }

        public void Update(PurchaseRecord record) {
            record.DateUpdated = DateTime.UtcNow;
            if (!string.IsNullOrEmpty(OperatorId)) {
                 record.OperatorId = OperatorId;
            }

            if (!string.IsNullOrEmpty(PostOperatorId)) {
                 record.PostOperatorId = PostOperatorId;
            }

            if (DatePurchased != null) {
                record.DateCreated = (DateTime) DatePurchased;
            }

            if (Count != null) {
                record.Count  = (int) Count;
            }

            if (Cost != null) {
                record.Cost = (decimal) Cost;
            }

            if (Rate != null) {
                record.CurrencyRate = (decimal) Rate;
            }
            if (Postage != null) {
                record.Postage = (decimal) Postage;
            }

            if (Location != null) {
                record.Location = (int) Location;
            }
        }

    }

}